JBoss Community Archive (Read Only)

Errai

Type-safe dynamic lookup

As an alternative to using the bean manager to dynamically create beans, this can be accomplished in a type-safe way by injecting a javax.enterprise.inject.Instance<T>.

For instance, assume you have a dependent-scoped bean Bar and consider the following:

public class Foo {
  @Inject Instance<Bar> barInstance;

  public void pingNewBar() {
    Bar bar = barInstance.get();
    bar.ping();
  }
}

In this example, calling barInstance.get() returns a new instance of the dependent-scoped bean Bar.

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-10 12:34:52 UTC, last content change 2012-09-05 19:39:43 UTC.